In [1]:
import wfdb
import numpy as np
import matplotlib.pyplot as plt
import sys
Downloading an ECG from mimic III
In [2]:
folder = "p05/p050140"
waveform = "p050140-2188-07-26-05-51"
sig, fields = wfdb.srdsamp(waveform,pbdir='mimic3wdb/matched/'+folder, sampto=150000)
In [3]:
print("signame: " + str(fields['signame']))
print("units: " + str(fields['units']))
print("fs: " + str(fields['fs']))
print("comments: " + str(fields['comments']))
print("fields: " + str(fields))
Lets check if the signal contains the signal II
In [4]:
signalII = None
try:
signalII = fields['signame'].index("II")
except ValueError:
print("List does not contain value")
if(signalII!=None):
print("List contain value")
Obtain only the signal II from the ECG
In [5]:
array = sig[:, signalII]
array = np.nan_to_num(array)
Save the Frame Secuence
In [6]:
fs = fields['fs']
fs
Out[6]:
Create Numpy Array
In [7]:
npArray = np.array(array)
npArray
Out[7]:
In [8]:
from oct2py import octave
octave.addpath('/home/scidb/HeartRatePatterns/Matlab/')
octave.eval('pkg load signal')
In [9]:
%load_ext oct2py.ipython
In [10]:
%%octave -i array,fs -o R_i,R_amp,S_i,S_amp,T_i,T_amp,Q_i,Q_amp,heart_rate,buffer_plot
[R_i,R_amp,S_i,S_amp,T_i,T_amp,Q_i,Q_amp,heart_rate,buffer_plot] = peakdetect(array,fs,false);
In [11]:
print("R_i",R_i)
print("S_i",S_i)
print("R_i",T_i)
print("Q_i",Q_i)
print(heart_rate)
print(buffer_plot)
In [12]:
To= 5
subarray = buffer_plot[0][Q_i[0][0]:T_i[0][To]]
print(len(subarray))
subQ_i = Q_i[0][:To]
subQ_amp = Q_amp[0][:To]
subR_i = R_i[0][:To]
subR_amp = R_amp[0][:To]
subS_i = S_i[0][:To]
subS_amp = S_amp[0][:To]
subT_i = T_i[0][:To]
subT_amp = T_amp[0][:To]
In [13]:
fig_size = [12,9]
plt.rcParams["figure.figsize"] = fig_size
In [14]:
plt.plot(np.arange(Q_i[0][0],T_i[0][To]),np.array(subarray),c='lightgreen')
plt.scatter(subQ_i, subQ_amp,c='yellow')
plt.scatter(subR_i, subR_amp,c='blue')
plt.scatter(subS_i, subS_amp,c='red')
plt.scatter(subT_i, subT_amp,c='black')
plt.show()
In [16]:
qt = Q_i[0][:209]-T_i
qt
Out[16]:
In [18]:
ts = T_i-S_i[0][:209]
ts
Out[18]:
In [19]:
sr = S_i-R_i
sr
Out[19]:
In [ ]: